Build Android with Gradle (Basic Config)

Manifest entries

  • minSdkVersion
  • targetSdkVersion
  • versionCode
  • versionName
  • applicationId
  • Package Name for the test application
  • Instrumentation test runner
example
1
2
3
4
5
6
7
8
9
10
11
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"

defaultConfig {
versionCode 12
versionName "2.0"
minSdkVersion 16
targetSdkVersion 16
}
}

Note : applicationId 取代在 manifest 的 packageName

也能夠使用 func
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def computeVersionName() {
...
}

android {
compileSdkVersion 19
buildToolsVersion "19.0.0"

defaultConfig {
versionCode 12
versionName computeVersionName()
minSdkVersion 16
targetSdkVersion 16
}
}

Config Property Table

Property Name Default value in DSL object Default value
versionCode -1 value from manifest if present
versionName null value from manifest if present
minSdkVersion -1 value from manifest if present
targetSdkVersion -1 value from manifest if present
applicationId null value from manifest if present
testApplicationId null applicationId + “.test”
testInstrumentationRunner null android.test.InstrumentationTestRunner
signingConfig null null
proguardFile N/A (set only) N/A (set only)
proguardFiles N/A (set only) N/A (set only)